﻿$(document).ready(function() {
    var deviceIDSet = false;
    $('#setDeviceIDButton').click(function() {
        if ($('#deviceID').val() == "") {
            $('#setPollLocationErrorMessage').text("DeviceID cannot be blank");
        }
        else {
            $.ajax({
                type: 'POST',
                url: "/Participant/AddTestParticipant",
                data: { deviceID: $('#deviceID').val(), pollID: $('#pollID').val() },
                success: function(response) {
                    if (response == "True") {
                        deviceIDSet = true;
                        $('#setDeviceIDButton').attr("disabled", true);
                        $('#setPollLocationErrorMessage').text("");
                    }
                    else {
                        $('#setPollLocationErrorMessage').text("Participant already in this poll");
                    }
                }
            });
        }
    });
    $('#runTestPollButton').click(function() {
        if (!deviceIDSet) {
            $('#setPollLocationErrorMessage').text("DeviceID cannot be blank");
        }
        else {
            window.open("/Poll/Run?pollID=" + $('#pollID').val() + "&testPoll=true");
        }
    });
    $('#respondByKeypadButton').click(function() {
        if (!deviceIDSet) {
            $('#setPollLocationErrorMessage').text("DeviceID cannot be blank");
        }
        else {
            window.open("/Screen/KeypadTest?pollID=" + $('#pollID').val() + "&show=Name");
        }
    });
    $('#respondByWebButton').click(function() {
        if (!deviceIDSet) {
            $('#setPollLocationErrorMessage').text("DeviceID cannot be blank");
        }
        else {
            window.open("/Respond/ResponseQuestions/?pollID=" + $('#pollID').val());
        }
    });
});